<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<%=basePath %>"/>
    <meta charset="UTF-8">
    <title>网上花店管理后台</title>
    <link rel="stylesheet" type="text/tailwindcss" href="${pageContext.request.contextPath}/style.css" />

    <!-- jQuery文件 -->
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery.tabify.js"></script>
    <script>
        var $ = jQuery.noConflict();
        $(function() {
            $('#tabsmenu').tabify();
            $(".toggle_container").hide();
            $(".trigger").click(function(){
                $(this).toggleClass("active").next().slideToggle("slow");
                return false;
            });
        });
        function changenum(id){
            var num = document.getElementById(id+"_num").value;
            var reg1 = /^\d+$/;
            if (num.match(reg1) == null) {
                alert("购买数量必须为正整数");
                return false;
            }
            if (num == 0) {
                alert("购买数量必须大于0的正整数");
                return false;
            }
            window.location.href="<%=basePath %>indexServlet/gouwucheupdate2?id="+id+"&number="+encodeURIComponent(num)+"&t="+new Date().getTime();
        }
    </script>
</head>
<body>
<div id="panelwrap">
    <!-- 头部包含 -->
    <%@ include file="../head.jsp" %>

    <div class="submenu"></div>

    <div class="center_content">
        <div id="right_wrap">
            <div id="right_content">
                <h2>我的购物车</h2>

                <!-- 错误消息显示 -->
                <c:if test="${not empty errorMsg}">
                    <div class="error-message text-red-500">${errorMsg}</div>
                </c:if>

                <table id="rounded-corner" class="w-full">
                    <thead>
                    <tr>
                        <th align="left" colspan="5">购物车列表</th>
                    </tr>
                    <tr>
                        <th align="left">商品名</th>
                        <th align="left">单价</th>
                        <th align="left">购买数量</th>
                        <th align="left">小计</th>
                        <th align="left">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <!-- 购物车为空的提示 -->
                    <c:if test="${empty list}">
                        <tr>
                            <td colspan="5" align="center" class="py-4">购物车为空</td>
                        </tr>
                    </c:if>

                    <!-- 购物车商品列表 -->
                    <c:forEach items="${list}" var="bean">
                        <tr class="odd">
                            <td><c:out value="${bean.pname}" /></td>
                            <td>￥${bean.jiage}</td>
                            <td>
                                <input type="text" name="number" value="${bean.shuliang}" id="${bean.id}_num" size="5"/>
                                <a href="javascript:;" onclick="changenum(${bean.id})">变更</a>
                            </td>
                            <td>￥${bean.jiage * bean.shuliang}</td>
                            <td>
                                <a href="indexServlet/gouwuchedelete?id=${bean.id}" onclick="return confirm('确定要删除吗?')">删除</a>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="5">
                                <span style="font-size: 30px;">
                                    总计：￥${zongjia}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="indexServlet/dingdanadd">结算，生成订单</a>
                                </span>
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
        <!-- 左侧菜单 -->
        <%@ include file="../left.jsp" %>
        <div class="clear"></div>
    </div>
</div>
</body>
</html>